<?php @session_start();?>
<?php
require_once('./safe.php');
require_once('../admin/config.php');
$conn = mysql_connect($cfg_dbhost,$cfg_dbuser,$cfg_dbpwd);
mysql_select_db($cfg_dbname,$conn);
function http_get($url){
$headers[] = "user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36";
//$headers[] = "Zoomkey-Auth-Token: 9CD0F0F60AFDF00";
$curl = curl_init(); // 启动一个CURL会话
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); // 跳过证书检查
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); // 从证书中检查SSL加密算法是否存在
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
$tmpInfo = curl_exec($curl);
curl_close($curl);
return $tmpInfo;
}
$app_id=$_POST["app_id"];
$sql="select * from ph_myapp where ID='".$app_id."'";
$result=mysql_query($sql);
$row=mysql_fetch_array($result);
$url=$row["url"];
$thetype=$row["icon"];
if(!empty($url)){
    $content = http_get($url);
    if(!empty($content)){
        if($thetype=="apple"){
            $img=explode("srcset=\"",$content);
            $icon=explode("1x,",$img[1]);

            $app=explode("title\" content=\"",$content);
            $app_name=explode("\" class=",$app[1]);
        }else{
            $img=explode("class=\"xSyT2c\"><img src=\"",$content);
            $icon=explode("\" srcset=\"",$img[1]);
            $app=explode("og:title\" content=\"",$content);
            $app_name=explode(" - Apps on Google",$app[1]);
        }
//echo $app_name[0];
        $sql = "update ph_myapp set app_name='".$app_name[0]."',icon='".$icon[0]."' where ID='".$app_id."'";
        mysql_query($sql,$conn);

        header("Content-type:application/json");
        echo "{\"status\":true,\"errors\":[\"0\"]}";
        exit;
    }else{
        header('Content-type:text/json');
        echo "{\"status\":false,\"errors\":[\"Didn't find a match on the package name, or could not fetch the App information\"]}";
        exit;
    }
}



?>